﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using ObjectLibrary;
using Particle3DEffect;
using Primitives3D;
using FighterLibrary;
namespace AIProcessor
{
    public class NoobControl : ComputerControl
    {
        public NoobControl(Fighter fighter,int team)
        {
            _fighter = fighter;
            _team = team;
        }
        public override void UpdateAction(Word outsideWord,Game game)
        {
            fireTime++;

            if (_targetFoe == null || _targetFoe.CurrentState == Fighter.State.dead)
            {
                _targetFoe = GetNewTarget(outsideWord);
            }
            else
            {
                float value = GetFitnessValue(_targetFoe, outsideWord.ListPlayers[_team]);
                float fireValue = GetFireFitnessValue(_targetFoe, outsideWord.ListPlayers[_team]);
                if (value > fireValue && value > 0)
                {
                    if (Moveto(_targetFoe.CurrentPosition, 5))
                    {
                        if (Fighter.getDeltaRotaionY(_fighter.LookRotationY, _fighter.RotationY) < MathHelper.PiOver4)
                        {
                            if (randomEngine.Next(25) == 0)
                                _fighter.AddToComboQueue(Move.Strike.PUNCH);
                            else if (randomEngine.Next(25) == 0)
                                _fighter.AddToComboQueue(Move.Strike.KICK);

                            _fighter.Actack();
                        }
                        else
                        {
                            
                            _fighter.Idle();
                        }
                    }
                }
                else if (value < fireValue && fireValue > 0)
                {
                    if (fireTime > startFireTime)
                    {
                        fireTime = 0;
                        startFireTime = 100 + randomEngine.Next(100);
                        _fighter.EnergySpheres.Add(new EnergySphere(game));
                        _fighter.ThrowEnergySphere(_targetFoe.CurrentPosition + new Vector3(
                    (float)randomEngine.NextDouble() * 2 - 1, (float)randomEngine.NextDouble() * 5, (float)randomEngine.NextDouble() * 2 - 1
                    ));
                    }
                    else
                    {
                        _fighter.IsFired = true;
                        RandomAcction();
                    }
                }
                else
                {
                    _targetFoe = GetNewTarget(outsideWord);
                    RandomAcction();
                }
            }

            

        }

    }
}
